package com.hm.jiaowuxitong.ui;

import com.hm.jiaowuxitong.util.DBUtil;
import com.hm.jiaowuxitong.util.UIUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class UpdataTeacherInfoUI {
    private int frame_width=800;
    private int frame_height=470;


    public UpdataTeacherInfoUI(){
        //创建添加学生信息的面板
        JFrame frame=new JFrame("修改教师信息");
        //设置面板的宽高
        frame.setSize(frame_width,frame_height);
        //禁止面板放大缩小
        frame.setResizable(false);
        //创建画布
        JPanel panel=new JPanel();
        //创建方向布局
        SpringLayout layout=new SpringLayout();
        panel.setLayout(layout);

        //创建文本框控件
        JLabel label1=new JLabel("教师号:");
        layout.putConstraint(SpringLayout.WEST,label1,230,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label1,50,SpringLayout.NORTH,panel);
        label1.setForeground(Color.black);
        label1.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf1=new JTextField(15);
        layout.putConstraint(SpringLayout.NORTH,jtf1,57,SpringLayout.NORTH,panel);
        layout.putConstraint(SpringLayout.WEST,jtf1,5,SpringLayout.EAST,label1);
        jtf1.setForeground(Color.black);
        jtf1.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label2=new JLabel("性别修改为:");
        layout.putConstraint(SpringLayout.WEST,label2,185,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label2,10,SpringLayout.SOUTH,label1);
        label2.setForeground(Color.black);
        label2.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf2=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf2,5,SpringLayout.EAST,label2);
        layout.putConstraint(SpringLayout.NORTH,jtf2,10,SpringLayout.SOUTH,jtf1);
        jtf2.setForeground(Color.black);
        jtf2.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label3=new JLabel("学历修改为:");
        layout.putConstraint(SpringLayout.WEST,label3,185,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label3,10,SpringLayout.SOUTH,label2);
        label3.setForeground(Color.black);
        label3.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf3=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf3,5,SpringLayout.EAST,label3);
        layout.putConstraint(SpringLayout.NORTH,jtf3,10,SpringLayout.SOUTH,jtf2);
        jtf3.setForeground(Color.black);
        jtf3.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label4=new JLabel("职称修改为:");
        layout.putConstraint(SpringLayout.WEST,label4,185,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label4,10,SpringLayout.SOUTH,label3);
        label4.setForeground(Color.black);
        label4.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf4=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf4,5,SpringLayout.EAST,label4);
        layout.putConstraint(SpringLayout.NORTH,jtf4,10,SpringLayout.SOUTH,jtf3);
        jtf4.setForeground(Color.black);
        jtf4.setFont(new Font(" ", 3, 15));
        //创建文本框控件
        JLabel label5=new JLabel("所属学院修改为:");
        layout.putConstraint(SpringLayout.WEST,label5,140,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label5,10,SpringLayout.SOUTH,label4);
        label5.setForeground(Color.black);
        label5.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf5=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf5,5,SpringLayout.EAST,label5);
        layout.putConstraint(SpringLayout.NORTH,jtf5,10,SpringLayout.SOUTH,jtf4);
        jtf5.setForeground(Color.black);
        jtf5.setFont(new Font(" ", 3, 15));

        JLabel label6=new JLabel("所带班级修改为:");
        layout.putConstraint(SpringLayout.WEST,label6,135,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,label6,10,SpringLayout.SOUTH,label5);
        label6.setForeground(Color.black);
        label6.setFont(new Font(" ", 3, 20));
        //创建文本编辑框控件
        JTextField jtf6=new JTextField(15);
        layout.putConstraint(SpringLayout.WEST,jtf6,5,SpringLayout.EAST,label6);
        layout.putConstraint(SpringLayout.NORTH,jtf6,10,SpringLayout.SOUTH,jtf5);
        jtf6.setForeground(Color.black);
        jtf6.setFont(new Font(" ", 3, 15));

        //创建提交按钮
        JButton button=new JButton("提交");
        layout.putConstraint(SpringLayout.WEST,button,305,SpringLayout.WEST,panel);
        layout.putConstraint(SpringLayout.NORTH,button,300,SpringLayout.NORTH,panel);
        button.setForeground(Color.black);
        button.setFont(new Font(" ", 3, 15));
        JButton button1=new JButton("返回");
        layout.putConstraint(SpringLayout.WEST,button1,20,SpringLayout.EAST,button);
        layout.putConstraint(SpringLayout.NORTH,button1,300,SpringLayout.NORTH,panel);
        button1.setForeground(Color.black);
        button1.setFont(new Font(" ", 3, 15));

        JLabel img=new JLabel();
        ImageIcon imageIcon = new ImageIcon(".idea/83@8C1~2U@T_%X7@`C9A9]D_tmb.jpg");  // 将"path/to/your/image.jpg"替换为你的图片路径
        img.setIcon(imageIcon);
        //把所有控件添加至画布

        panel.add(label1);
        panel.add(jtf1);
        panel.add(label2);
        panel.add(jtf2);
        panel.add(label3);
        panel.add(jtf3);
        panel.add(label4);
        panel.add(jtf4);
        panel.add(label5);
        panel.add(jtf5);
        panel.add(label6);
        panel.add(jtf6);

        panel.add(button);
        panel.add(button1);
        panel.add(img);
        //把画布添加至面板
        frame.setContentPane(panel);
        //将面板中央显示
        new UIUtil().center(frame,frame_width,frame_height);
        //将面板显示
        frame.setVisible(true);
        //添加提交按钮的点击事件
        button.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {
                //获得所有编辑框中添加的内容信息

                String name=jtf1.getText();
                String sex=jtf2.getText();
                String graduation=jtf3.getText();
                String job=jtf4.getText();
                String academy=jtf5.getText();
                String LeadClass=jtf6.getText();
                if (!sex.isEmpty()&&!name.isEmpty())  {
                    UpdateTeacherSex(name,sex);
                    System.out.println("修改性别成功");
                    // 处理文本框已输入的情况
                }
                if (!graduation.isEmpty()&&!name.isEmpty())  {
                    UpdateTeacherGraduation(name,graduation);
                    System.out.println("修改学历成功");
                    // 处理文本框已输入的情况
                }
                if (!job.isEmpty()&&!name.isEmpty())  {
                    UpdateTeacherJob(name,job);
                    System.out.println("修改职称成功");
                    // 处理文本框已输入的情况
                }
                if (!academy.isEmpty()&&!name.isEmpty())  {
                    UpdateTeacherAcademy(name,academy);
                    System.out.println("修改所属学院成功");
                    // 处理文本框已输入的情况
                }
                if (!LeadClass.isEmpty()&&!name.isEmpty())  {
                    UpdateTeacherLeadClass(name,LeadClass);
                    System.out.println("修改所带班级成功");
                    // 处理文本框已输入的情况
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        button1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {
                new AdministratorGui();
                frame.dispose();

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });



    }

    public void delete(String id){
        DBUtil.jt.update("delete from 教师表 where 姓名=?", new Object[]{id});


//        System.out.println(
//                (jt.update("delete from tb_student where id=?", new Object[]{21})>0
//                        ?"删除成功":"删除失败"));
    }
    public void UpdateTeacherGraduation(String id,String age){
        DBUtil.jt.update("update 教师表 set 学历=? where 教师号=?",
                new Object[]{age, id});

    }
    public void UpdateTeacherSex(String id,String sex){
        DBUtil.jt.update("update 教师表 set 性别=? where 教师号=?",
                new Object[]{sex, id});

    }
    public void UpdateTeacherJob(String id,String sex){
        DBUtil.jt.update("update 教师表 set 职称=? where 教师号=?",
                new Object[]{sex, id});

    }
    public void UpdateTeacherAcademy(String id,String sex){
        DBUtil.jt.update("update 教师表 set 所属学院=? where 教师号=?",
                new Object[]{sex, id});

    }
    public void UpdateTeacherLeadClass(String id,String sex){
        DBUtil.jt.update("update 教师表 set 所带班级=? where 教师号=?",
                new Object[]{sex, id});

    }

    public static void main(String[] args) {
        new UpdataTeacherInfoUI();
    }
}
